<template>
  <div class="DocumentTemplate">
    <!-- 页面主体信息区域 -->
    <van-tree-select
      @click-nav="clickNav"
      height="100%"
      :items="items"
      :main-active-index.sync="activeIndex"
    >
      <div slot="content">
        <van-cell-group>
          <van-cell
            v-show="items.length"
            v-for="(item, index) in items[activeIndex].options"
            :key="index"
            is-link
            :to="{ path: '/Document', query: { item: JSON.stringify(item) }}"
            :title="item.title"
            :label="item.categoryName"
          />
        </van-cell-group>
      </div>
    </van-tree-select>
  </div>
</template>
<script>
export default {
  name: "DocumentTemplate",
  data() {
    return {
      activeIndex: 0,
      items: [
        {
          options: []
        }
      ]
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.$toast.loading({
        message: "加载中...",
        forbidClick: true
      });
      this.slow.getDictionaryValus("wsfb").then(ret => {
        ret.forEach(e => {
          e.options = [];
        });
        this._getData(ret[0].value, data => {
          ret[0].options = data;
          this.items = ret;
          this.$toast.clear();
        });
      });
      this._getData();
    });
  },
  methods: {
    clickNav(index) {
      this._getData(this.items[index].value, data => {
        this.items[index].options = data;
      });
    },
    _getData(type, cb) {
      if (this.slow.documenttest) {
        const data = require("@/assets/dt.json");
        cb && cb(data.array);
      } else {
        this.post("/document_template/loadInfo?pageIndex=1&pageSize=3000", {
          pageIndex: 1,
          pageSize: 3000,
          type: type
        })
          .then(res => {
            cb && cb(res.array || []);
          })
          .catch(err => {});
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import "~@/smobile.scss";
.van-sidebar-item--select {
  border-color: #10b463;
}
</style>